package com.wmh.baseservice.admin.pojo.vo.menu;

import com.wmh.baseservice.admin.entity.AdMenu;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 谢骏
 * @date 2023/7/2 16:03
 **/
@ApiModel("树级菜单VO对象")
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class MenuTreeVo extends BaseVO{

    @ApiModelProperty(value = "子菜单")
    private List<MenuTreeVo> children;

    public static MenuTreeVo build(AdMenu source) {
        MenuTreeVo menuTreeVo = new MenuTreeVo();
        menuTreeVo.setId(source.getId());
        menuTreeVo.setMenuName(source.getMenuName());
        menuTreeVo.setPermissions(source.getPermissions());
        menuTreeVo.setRequestUrl(source.getRequestUrl());
        menuTreeVo.setMenuIcon(source.getMenuIcon());
        menuTreeVo.setParentId(source.getParentId());
        menuTreeVo.setComponent(source.getComponent());
        menuTreeVo.setFlag(source.getFlag());
        menuTreeVo.setSort(source.getSort());
        return menuTreeVo;
    }

    public static List<MenuTreeVo> build(List<AdMenu> sources) {
        return sources.stream().map(MenuTreeVo::build).collect(Collectors.toList());
    }
}
